package cn.ren.service;

import cn.ren.dao.MemberDao;
import cn.ren.dao.OrderDao;
import cn.ren.util.DateUtils;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: itcast_health
 * @description:
 * @author: ren
 * @create: 2020-03-05 17:11
 **/
@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {
    @Autowired
    private MemberDao memberDao;
    @Autowired
    private OrderDao orderDao;

    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {
        /* reportDate:null,
            todayNewMember :2,
            totalMember :3,
            thisWeekNewMember :2,
            thisMonthNewMember :2,
            todayOrderNumber :0,
            todayVisitsNumber :0,
            thisWeekOrderNumber :0,
            thisWeekVisitsNumber :0,
            thisMonthOrderNumber :0,
            thisMonthVisitsNumber :0,
            hotSetmeal :[
                {name:'阳光爸妈升级肿瘤12项筛查（男女单人）体检套餐',setmeal_count:200,proportion:0.222},
                {name:'阳光爸妈升级肿瘤12项筛查体检套餐',setmeal_count:200,proportion:0.222}
            ]
                }*/
        //获取当前日期
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        //获取本周第一天日期
        String firstDayOfWeek = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //获取本月第一天日期
        String firstDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        //获取会员相关数据
        /*todayNewMember :2,
         totalMember :3,
         thisWeekNewMember :2,
         thisMonthNewMember :2,*/
        Integer todayNewMember = memberDao.findTodayNewMemberCount(today);
        Integer totalMember = memberDao.findTotalCount();
        Integer thisWeekNewMember = memberDao.findThisWeekNewMemberCount(firstDayOfWeek);
        Integer thisMonthNewMember = memberDao.findThisMonthNewMemberCount(firstDay4ThisMonth);
        //获取预约相关数据
        /*todayOrderNumber :0,
        thisWeekOrderNumber :0,
        thisMonthOrderNumber :0,
        */
        Integer todayOrderNumber = orderDao.findTodayOrderCount(today);
        Integer thisWeekOrderNumber = orderDao.findThisWeekOrderNumber(firstDayOfWeek);
        Integer thisMonthOrderNumber = orderDao.findThisMonthOrderNumber(firstDay4ThisMonth);
        //获取到诊数据
        Integer todayVisitsNumber = orderDao.findTodayVisitCount(today);
        Integer thisWeekVisitsNumber = orderDao.findWeekVisitCount(firstDayOfWeek);
        Integer thisMonthVisitsNumber = orderDao.findMonthVisitCount(firstDay4ThisMonth);
        //查询热门套餐
        List<Map<String,Object>> hotSetmeal = orderDao.findHotSetmeal();
        //封装数据到map容器里
        Map<String,Object> result = new HashMap<>();
        result.put("reportDate",today);
        result.put("todayNewMember",todayNewMember);
        result.put("totalMember",totalMember);
        result.put("thisWeekNewMember",thisWeekNewMember);
        result.put("thisMonthNewMember",thisMonthNewMember);
        result.put("todayOrderNumber",todayOrderNumber);
        result.put("thisWeekOrderNumber",thisWeekOrderNumber);
        result.put("thisMonthOrderNumber",thisMonthOrderNumber);
        result.put("todayVisitsNumber",todayVisitsNumber);
        result.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        result.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        result.put("hotSetmeal",hotSetmeal);
        return result;
    }
}
